import legacyPlugin from '@vitejs/plugin-legacy';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import autoImport from "unplugin-auto-import/vite";
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig } from 'vite';
import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import';

// https://vitejs.dev/config/
export default defineConfig({
  publicDir:'',
  plugins: [
    vue(),
    Components({
      resolvers: [AntDesignVueResolver()],
    }),
    autoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/ // .vue
      ],
      imports: ['vue', 'vue-router', 'pinia'],
      eslintrc: {
        enabled: false, // 若没此json文件，先开启，生成后在关闭
        filepath: './.eslintrc-auto-import.json', // 设置eslintrc-auto-import.json生成路径 Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      dts: 'typings/auto-imports.d.ts' // 设置auto-import.d.ts生成路径 Default ./auto-imports.d.ts
    }),
    createStyleImportPlugin({
      resolves: [
        VxeTableResolve()
      ],
    }),
    legacyPlugin({
      targets:['chrome 52', 'Safari  12.1', 'ios >= 12.3'],  // 需要兼容的目标列表，可以设置多个
      additionalLegacyPolyfills:['regenerator-runtime/runtime'] // 面向IE11时需要此插件
  })
  ],
  server: {
    host: '0.0.0.0'
  },
  resolve:{
    alias:{
      '@': resolve(__dirname, 'src')
    }
  },
  build: {
    outDir: 'dist',
    target: ['es2015'], // 这一段必填
 }
})
